package ligapes.model.dao;

import java.util.List;

import ligapes.util.HibernateUtil;

import org.hibernate.Session;

public class DAO<T> {

	private Session session;
	private final Class<T> classe;
	
	public DAO(Class<T> classe) {
		this.classe = classe;
		this.session = HibernateUtil.getSessionFactory().getCurrentSession();
	}
	
	public void salvar(T t) {
		this.session.save(t);
	}
	
	public void atualizar(T t) {
		this.session.update(t);
	}
	
	public void excluir(T t) {
		this.session.delete(t);
	}
	
	public T carregarPorId(Integer id) {
		return (T) this.session.get(this.classe, id);
	}
	
	public List<T> listar() {
		return this.session.createCriteria(this.classe).list();
	}
}
